layui.extend({
    admin: '/static/background/js/admin'
});
layui.use(['form'], function () {
    var form = layui.form,
        $ = layui.jquery;
    form.on('submit(login)', function (data) {
        let username = $("input[name=username]").val();
        let password = $("input[name=password]").val();
        $.ajax({
            type: "POST",
            url: '/api/admin/auth',
            dataType: 'json',
            data: {
                username: username,
                password: password,
            },
            success: function (data) {
                if (data.status === 200) {
                    localStorage.id = data.data.id
                    localStorage.name = data.data.name
                    localStorage.Authorization = data.data.Authorization
                    localStorage.photo = data.data.photo
                    localStorage.admin = 1
                    location.href = '/back/index'
                } else {
                    layui.use('layer', function () {
                        layer.msg(data.msg)
                    });
                }
            },
            err: function () {
                layui.use('layer', function () {
                    layer.msg("服务器请求失败")
                });
            }
        });
        return false;
    });
});